package com.gxgeek.javabasic.api;


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by gx on 2017/7/10.
 */
public class RenderReverse {

    /**
     * status : 0
     * result : {"location":{"lng":116.32298699999993,"lat":39.98342407140365},"formatted_address":"北京市海淀区中关村大街27号1101-08室","business":"中关村,人民大学,苏州街","addressComponent":{"country":"中国","country_code":0,"province":"北京市","city":"北京市","district":"海淀区","adcode":"110108","street":"中关村大街","street_number":"27号1101-08室","direction":"附近","distance":"7"},"pois":[{"addr":"北京北京海淀海淀区中关村大街27号（地铁海淀黄庄站A1","cp":"","direction":"内","distance":"0","name":"北京远景国际公寓(中关村店)","poiType":"房地产","point":{"x":116.32294589160055,"y":39.983610361549296},"tag":"房地产","tel":"","uid":"35a08504cb51b1138733049d","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}},{"addr":"海淀区中关村北大街27号","cp":" ","direction":"附近","distance":"26","name":"中关村大厦","poiType":"房地产","point":{"x":116.32288301021485,"y":39.98358962971618},"tag":"房地产;写字楼","tel":"","uid":"06d2dffdaef1b7ef88f15d04","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}},{"addr":"北京市海淀区中关村大街27号中关村大厦二层","cp":" ","direction":"附近","distance":"5","name":"眉州东坡酒楼(中关村店)","poiType":"美食","point":{"x":116.32293690854546,"y":39.98343759607948},"tag":"美食;中餐厅","tel":"","uid":"2c0bd6c57dbdd3b342ab9a8c","zip":"","parent_poi":{"name":"中关村大厦","tag":"房地产;写字楼","addr":"海淀区中关村北大街27号","point":{"x":116.32288301021485,"y":39.98358962971618},"direction":"附近","distance":"26","uid":"06d2dffdaef1b7ef88f15d04"}},{"addr":"海淀区中关村大街27号中关村大厦(近海淀医院)","cp":" ","direction":"附近","distance":"41","name":"中国建设银行(中关村支行)","poiType":"金融","point":{"x":116.32291894243525,"y":39.98370711002003},"tag":"金融;银行","tel":"","uid":"14076deea757edf402294f41","zip":"","parent_poi":{"name":"中关村大厦","tag":"房地产;写字楼","addr":"海淀区中关村北大街27号","point":{"x":116.32288301021485,"y":39.98358962971618},"direction":"附近","distance":"26","uid":"06d2dffdaef1b7ef88f15d04"}},{"addr":"中关村大街27号中关村大厦(东门)附近","cp":" ","direction":"附近","distance":"45","name":"北京市海淀医院-东北1门","poiType":"出入口","point":{"x":116.32331419685964,"y":39.983230276934485},"tag":"出入口;门","tel":"","uid":"d8862bd634393eac93114c69","zip":"","parent_poi":{"name":"海淀医院","tag":"医疗;综合医院","addr":"北京市海淀区中关村大街29号","point":{"x":116.32195775553959,"y":39.98278108327827},"direction":"东北","distance":"147","uid":"fa01e9371a040053774ff1ca"}},{"addr":"北京市海淀区中关村大厦21层","cp":" ","direction":"附近","distance":"50","name":"艾博瑞教育北京校区","poiType":"教育培训","point":{"x":116.32255063717616,"y":39.98350670232026},"tag":"教育培训;其他","tel":"","uid":"626e202852d111542dfaa76c","zip":"","parent_poi":{"name":"中关村大厦","tag":"房地产;写字楼","addr":"海淀区中关村北大街27号","point":{"x":116.32288301021485,"y":39.98358962971618},"direction":"附近","distance":"26","uid":"06d2dffdaef1b7ef88f15d04"}},{"addr":"中关村大街29","cp":" ","direction":"北","distance":"62","name":"北京市海淀医院-激光整形美容部","poiType":"医疗","point":{"x":116.32317046797804,"y":39.983016046485126},"tag":"医疗;专科医院","tel":"","uid":"b1c556e81f27cb71b4265502","zip":"","parent_poi":{"name":"海淀医院","tag":"医疗;综合医院","addr":"北京市海淀区中关村大街29号","point":{"x":116.32195775553959,"y":39.98278108327827},"direction":"东北","distance":"147","uid":"fa01e9371a040053774ff1ca"}},{"addr":"中关村大街19号新中关大厦(近丹棱街)","cp":" ","direction":"东南","distance":"181","name":"新中关购物中心","poiType":"购物","point":{"x":116.32176911138248,"y":39.984259955775116},"tag":"购物;购物中心","tel":"","uid":"8d96925c0372e65cc1f1cf7f","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}},{"addr":"中关村大街19号新中关大厦C座11层近地铁十号线海淀黄庄站新中关商场海淀医院人民大学国家图书馆","cp":" ","direction":"东南","distance":"130","name":"北京七喜酒店公寓(海淀黄庄店)","poiType":"房地产","point":{"x":116.32239792523947,"y":39.9842046714025},"tag":"房地产;住宅区","tel":"","uid":"9b285eb82ff8da77077ce8b1","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}},{"addr":"北京市海淀区丹棱街6号","cp":" ","direction":"东","distance":"286","name":"中国招商银行小企业信贷","poiType":"金融","point":{"x":116.32054741588891,"y":39.98405263914538},"tag":"金融;银行","tel":"","uid":"6e55fee8b37a5b0a631809d2","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}}],"roads":[],"poiRegions":[],"sematic_description":"北京远景国际公寓(中关村店)内0米","cityCode":131}
     */

    private int status;
    private ResultBean result;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public ResultBean getResult() {
        return result;
    }

    public void setResult(ResultBean result) {
        this.result = result;
    }

    public static class ResultBean {
        /**
         * location : {"lng":116.32298699999993,"lat":39.98342407140365}
         * formatted_address : 北京市海淀区中关村大街27号1101-08室
         * business : 中关村,人民大学,苏州街
         * addressComponent : {"country":"中国","country_code":0,"province":"北京市","city":"北京市","district":"海淀区","adcode":"110108","street":"中关村大街","street_number":"27号1101-08室","direction":"附近","distance":"7"}
         * pois : [{"addr":"北京北京海淀海淀区中关村大街27号（地铁海淀黄庄站A1","cp":"","direction":"内","distance":"0","name":"北京远景国际公寓(中关村店)","poiType":"房地产","point":{"x":116.32294589160055,"y":39.983610361549296},"tag":"房地产","tel":"","uid":"35a08504cb51b1138733049d","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}},{"addr":"海淀区中关村北大街27号","cp":" ","direction":"附近","distance":"26","name":"中关村大厦","poiType":"房地产","point":{"x":116.32288301021485,"y":39.98358962971618},"tag":"房地产;写字楼","tel":"","uid":"06d2dffdaef1b7ef88f15d04","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}},{"addr":"北京市海淀区中关村大街27号中关村大厦二层","cp":" ","direction":"附近","distance":"5","name":"眉州东坡酒楼(中关村店)","poiType":"美食","point":{"x":116.32293690854546,"y":39.98343759607948},"tag":"美食;中餐厅","tel":"","uid":"2c0bd6c57dbdd3b342ab9a8c","zip":"","parent_poi":{"name":"中关村大厦","tag":"房地产;写字楼","addr":"海淀区中关村北大街27号","point":{"x":116.32288301021485,"y":39.98358962971618},"direction":"附近","distance":"26","uid":"06d2dffdaef1b7ef88f15d04"}},{"addr":"海淀区中关村大街27号中关村大厦(近海淀医院)","cp":" ","direction":"附近","distance":"41","name":"中国建设银行(中关村支行)","poiType":"金融","point":{"x":116.32291894243525,"y":39.98370711002003},"tag":"金融;银行","tel":"","uid":"14076deea757edf402294f41","zip":"","parent_poi":{"name":"中关村大厦","tag":"房地产;写字楼","addr":"海淀区中关村北大街27号","point":{"x":116.32288301021485,"y":39.98358962971618},"direction":"附近","distance":"26","uid":"06d2dffdaef1b7ef88f15d04"}},{"addr":"中关村大街27号中关村大厦(东门)附近","cp":" ","direction":"附近","distance":"45","name":"北京市海淀医院-东北1门","poiType":"出入口","point":{"x":116.32331419685964,"y":39.983230276934485},"tag":"出入口;门","tel":"","uid":"d8862bd634393eac93114c69","zip":"","parent_poi":{"name":"海淀医院","tag":"医疗;综合医院","addr":"北京市海淀区中关村大街29号","point":{"x":116.32195775553959,"y":39.98278108327827},"direction":"东北","distance":"147","uid":"fa01e9371a040053774ff1ca"}},{"addr":"北京市海淀区中关村大厦21层","cp":" ","direction":"附近","distance":"50","name":"艾博瑞教育北京校区","poiType":"教育培训","point":{"x":116.32255063717616,"y":39.98350670232026},"tag":"教育培训;其他","tel":"","uid":"626e202852d111542dfaa76c","zip":"","parent_poi":{"name":"中关村大厦","tag":"房地产;写字楼","addr":"海淀区中关村北大街27号","point":{"x":116.32288301021485,"y":39.98358962971618},"direction":"附近","distance":"26","uid":"06d2dffdaef1b7ef88f15d04"}},{"addr":"中关村大街29","cp":" ","direction":"北","distance":"62","name":"北京市海淀医院-激光整形美容部","poiType":"医疗","point":{"x":116.32317046797804,"y":39.983016046485126},"tag":"医疗;专科医院","tel":"","uid":"b1c556e81f27cb71b4265502","zip":"","parent_poi":{"name":"海淀医院","tag":"医疗;综合医院","addr":"北京市海淀区中关村大街29号","point":{"x":116.32195775553959,"y":39.98278108327827},"direction":"东北","distance":"147","uid":"fa01e9371a040053774ff1ca"}},{"addr":"中关村大街19号新中关大厦(近丹棱街)","cp":" ","direction":"东南","distance":"181","name":"新中关购物中心","poiType":"购物","point":{"x":116.32176911138248,"y":39.984259955775116},"tag":"购物;购物中心","tel":"","uid":"8d96925c0372e65cc1f1cf7f","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}},{"addr":"中关村大街19号新中关大厦C座11层近地铁十号线海淀黄庄站新中关商场海淀医院人民大学国家图书馆","cp":" ","direction":"东南","distance":"130","name":"北京七喜酒店公寓(海淀黄庄店)","poiType":"房地产","point":{"x":116.32239792523947,"y":39.9842046714025},"tag":"房地产;住宅区","tel":"","uid":"9b285eb82ff8da77077ce8b1","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}},{"addr":"北京市海淀区丹棱街6号","cp":" ","direction":"东","distance":"286","name":"中国招商银行小企业信贷","poiType":"金融","point":{"x":116.32054741588891,"y":39.98405263914538},"tag":"金融;银行","tel":"","uid":"6e55fee8b37a5b0a631809d2","zip":"","parent_poi":{"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}}]
         * roads : []
         * poiRegions : []
         * sematic_description : 北京远景国际公寓(中关村店)内0米
         * cityCode : 131
         */

        private LocationBean location;
        private String formatted_address;
        private String business;
        private AddressComponentBean addressComponent;
        private String sematic_description;
        private int cityCode;
        private List<PoisBean> pois;
        private List<?> roads;
        private List<?> poiRegions;

        public LocationBean getLocation() {
            return location;
        }

        public void setLocation(LocationBean location) {
            this.location = location;
        }

        public String getFormatted_address() {
            return formatted_address;
        }

        public void setFormatted_address(String formatted_address) {
            this.formatted_address = formatted_address;
        }

        public String getBusiness() {
            return business;
        }

        public void setBusiness(String business) {
            this.business = business;
        }

        public AddressComponentBean getAddressComponent() {
            return addressComponent;
        }

        public void setAddressComponent(AddressComponentBean addressComponent) {
            this.addressComponent = addressComponent;
        }

        public String getSematic_description() {
            return sematic_description;
        }

        public void setSematic_description(String sematic_description) {
            this.sematic_description = sematic_description;
        }

        public int getCityCode() {
            return cityCode;
        }

        public void setCityCode(int cityCode) {
            this.cityCode = cityCode;
        }

        public List<PoisBean> getPois() {
            return pois;
        }

        public void setPois(List<PoisBean> pois) {
            this.pois = pois;
        }

        public List<?> getRoads() {
            return roads;
        }

        public void setRoads(List<?> roads) {
            this.roads = roads;
        }

        public List<?> getPoiRegions() {
            return poiRegions;
        }

        public void setPoiRegions(List<?> poiRegions) {
            this.poiRegions = poiRegions;
        }

        public static class LocationBean {
            /**
             * lng : 116.32298699999993
             * lat : 39.98342407140365
             */

            private double lng;
            private double lat;

            public double getLng() {
                return lng;
            }

            public void setLng(double lng) {
                this.lng = lng;
            }

            public double getLat() {
                return lat;
            }

            public void setLat(double lat) {
                this.lat = lat;
            }
        }

        public static class AddressComponentBean {
            /**
             * country : 中国
             * country_code : 0
             * province : 北京市
             * city : 北京市
             * district : 海淀区
             * adcode : 110108
             * street : 中关村大街
             * street_number : 27号1101-08室
             * direction : 附近
             * distance : 7
             */

            private String country;
            private int country_code;
            private String province;
            private String city;
            private String district;
            private String adcode;
            private String street;
            private String street_number;
            private String direction;
            private String distance;

            public String getCountry() {
                return country;
            }

            public void setCountry(String country) {
                this.country = country;
            }

            public int getCountry_code() {
                return country_code;
            }

            public void setCountry_code(int country_code) {
                this.country_code = country_code;
            }

            public String getProvince() {
                return province;
            }

            public void setProvince(String province) {
                this.province = province;
            }

            public String getCity() {
                return city;
            }

            public void setCity(String city) {
                this.city = city;
            }

            public String getDistrict() {
                return district;
            }

            public void setDistrict(String district) {
                this.district = district;
            }

            public String getAdcode() {
                return adcode;
            }

            public void setAdcode(String adcode) {
                this.adcode = adcode;
            }

            public String getStreet() {
                return street;
            }

            public void setStreet(String street) {
                this.street = street;
            }

            public String getStreet_number() {
                return street_number;
            }

            public void setStreet_number(String street_number) {
                this.street_number = street_number;
            }

            public String getDirection() {
                return direction;
            }

            public void setDirection(String direction) {
                this.direction = direction;
            }

            public String getDistance() {
                return distance;
            }

            public void setDistance(String distance) {
                this.distance = distance;
            }
        }

        public static class PoisBean {
            /**
             * addr : 北京北京海淀海淀区中关村大街27号（地铁海淀黄庄站A1
             * cp :
             * direction : 内
             * distance : 0
             * name : 北京远景国际公寓(中关村店)
             * poiType : 房地产
             * point : {"x":116.32294589160055,"y":39.983610361549296}
             * tag : 房地产
             * tel :
             * uid : 35a08504cb51b1138733049d
             * zip :
             * parent_poi : {"name":"","tag":"","addr":"","point":{"x":0,"y":0},"direction":"","distance":"","uid":""}
             */

            private String addr;
            private String cp;
            private String direction;
            private String distance;
            private String name;
            private String poiType;
            private PointBean point;
            private String tag;
            private String tel;
            private String uid;
            private String zip;
            private ParentPoiBean parent_poi;

            public String getAddr() {
                return addr;
            }

            public void setAddr(String addr) {
                this.addr = addr;
            }

            public String getCp() {
                return cp;
            }

            public void setCp(String cp) {
                this.cp = cp;
            }

            public String getDirection() {
                return direction;
            }

            public void setDirection(String direction) {
                this.direction = direction;
            }

            public String getDistance() {
                return distance;
            }

            public void setDistance(String distance) {
                this.distance = distance;
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public String getPoiType() {
                return poiType;
            }

            public void setPoiType(String poiType) {
                this.poiType = poiType;
            }

            public PointBean getPoint() {
                return point;
            }

            public void setPoint(PointBean point) {
                this.point = point;
            }

            public String getTag() {
                return tag;
            }

            public void setTag(String tag) {
                this.tag = tag;
            }

            public String getTel() {
                return tel;
            }

            public void setTel(String tel) {
                this.tel = tel;
            }

            public String getUid() {
                return uid;
            }

            public void setUid(String uid) {
                this.uid = uid;
            }

            public String getZip() {
                return zip;
            }

            public void setZip(String zip) {
                this.zip = zip;
            }

            public ParentPoiBean getParent_poi() {
                return parent_poi;
            }

            public void setParent_poi(ParentPoiBean parent_poi) {
                this.parent_poi = parent_poi;
            }

            public static class PointBean {
                /**
                 * x : 116.32294589160055
                 * y : 39.983610361549296
                 */

                private double x;
                private double y;

                public double getX() {
                    return x;
                }

                public void setX(double x) {
                    this.x = x;
                }

                public double getY() {
                    return y;
                }

                public void setY(double y) {
                    this.y = y;
                }
            }

            public static class ParentPoiBean {
                /**
                 * name :
                 * tag :
                 * addr :
                 * point : {"x":0,"y":0}
                 * direction :
                 * distance :
                 * uid :
                 */

                private String name;
                private String tag;
                private String addr;
                private PointBeanX point;
                private String direction;
                private String distance;
                private String uid;

                public String getName() {
                    return name;
                }

                public void setName(String name) {
                    this.name = name;
                }

                public String getTag() {
                    return tag;
                }

                public void setTag(String tag) {
                    this.tag = tag;
                }

                public String getAddr() {
                    return addr;
                }

                public void setAddr(String addr) {
                    this.addr = addr;
                }

                public PointBeanX getPoint() {
                    return point;
                }

                public void setPoint(PointBeanX point) {
                    this.point = point;
                }

                public String getDirection() {
                    return direction;
                }

                public void setDirection(String direction) {
                    this.direction = direction;
                }

                public String getDistance() {
                    return distance;
                }

                public void setDistance(String distance) {
                    this.distance = distance;
                }

                public String getUid() {
                    return uid;
                }

                public void setUid(String uid) {
                    this.uid = uid;
                }

                public static class PointBeanX {
                    /**
                     * x : 0
                     * y : 0
                     */

                    private int x;
                    private int y;

                    public int getX() {
                        return x;
                    }

                    public void setX(int x) {
                        this.x = x;
                    }

                    public int getY() {
                        return y;
                    }

                    public void setY(int y) {
                        this.y = y;
                    }
                }
            }
        }
    }


//    public static void main(String[] args) throws HttpProcessException, UnsupportedEncodingException {
//
//        String lat ="39.983424";
//        String lon ="116.322987";
//        String location = new StringBuilder(lat).append(",").append(lon).toString();
//
//        Map paramsMap = new LinkedHashMap<String, String>();
//        paramsMap.put("location", location);
//        paramsMap.put("output", "json");
//        paramsMap.put("pois", "1");
//        paramsMap.put("ak", "9zIkIhhorTTZoZGdhDNlKl36Mf1VmcPG");
//        String paramsStr = toQueryString(paramsMap);
//
//        String tempStrSn = new StringBuilder().append("/geocoder/v2/?").append(paramsStr).append("ILOTFGLHV3KyYFFnZwVA4y7R3AMNfCha").toString();
//        tempStrSn = URLEncoder.encode(tempStrSn, "UTF-8");
//        // 调用下面的MD5方法得到最后的sn签名7de5a22212ffaa9e326444c75a58f9a0
//        String sn = MD5(tempStrSn);
//
//        String url = new StringBuilder("http://api.map.baidu.com/geocoder/v2/?")
//                                       .append(paramsStr)
////                                        .append("&sn=").append(sn)
//                                        .toString();
//        System.out.println(url);
////        HttpConfig config = HttpConfig.custom()
////                .url(url)                    //设置请求的url
////                .encoding("utf-8"); //设置请求和返回编码，默认就是Charset.defaultCharset()
////
////        String result = HttpClientUtil.get(config);    //post请求
////        RenderReverse renderReverse = JSON.parseObject(result, RenderReverse.class);
////        System.out.println(renderReverse.getResult().formatted_address);
//    }

    public static String toQueryString(Map<?, ?> data)
            throws UnsupportedEncodingException {
        StringBuffer queryString = new StringBuffer();
        for (Map.Entry<?, ?> pair : data.entrySet()) {
            queryString.append(pair.getKey() + "=");
            queryString.append(URLEncoder.encode((String) pair.getValue(),
                    "UTF-8") + "&");
        }
        if (queryString.length() > 0) {
            queryString.deleteCharAt(queryString.length() - 1);
        }
        return queryString.toString();
    }
    public static String MD5(String md5) {
        try {
            java.security.MessageDigest md = java.security.MessageDigest
                    .getInstance("MD5");
            byte[] array = md.digest(md5.getBytes());
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < array.length; ++i) {
                sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100)
                        .substring(1, 3));
            }
            return sb.toString();
        } catch (java.security.NoSuchAlgorithmException e) {
        }
        return null;
    }


}
